home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / zoo tutorial / module 9- full screen mode / source / zoopane.java < prev   
Encoding:
Java Source  |  2000-06-23  |  7.6 KB  |  235 lines

  1. import java.awt.AWTEventMulticaster;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.awt.event.MouseListener;
  5. import java.awt.event.MouseEvent;
  6. import java.awt.Point;
  7. import java.util.Hashtable;
  8.  
  9. import quicktime.QTException;
  10. import quicktime.app.anim.Compositor;
  11. import quicktime.app.anim.TwoDSprite;
  12.  
  13. import quicktime.app.event.QTMouseTargetController;
  14. import quicktime.app.event.MouseButtonListener;
  15. import quicktime.app.event.MouseTargetAdapter;
  16. import quicktime.app.event.QTMouseEvent;
  17.  
  18. import quicktime.qd.QDColor;
  19. import quicktime.qd.QDConstants;
  20. import quicktime.std.image.GraphicsMode;
  21.  
  22. /**
  23.  * QTZoo Module 8 - Using QuickTime Transitions 
  24.  * The pane that specifies common behavior for all of the panes in the zoo project
  25.  *
  26.  * @author Levi Brown
  27.  * @author Michael Hopkins
  28.  * @author Apple Computer, Inc.
  29.  * @version 8.0 4/10/2000
  30.  * Copyright:     © Copyright 1999 Apple Computer, Inc. All rights reserved.
  31.  *    
  32.  * Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  33.  *                ("Apple") in consideration of your agreement to the following terms, and your
  34.  *                use, installation, modification or redistribution of this Apple software
  35.  *                constitutes acceptance of these terms.  If you do not agree with these terms,
  36.  *                please do not use, install, modify or redistribute this Apple software.
  37.  *
  38.  *                In consideration of your agreement to abide by the following terms, and subject
  39.  *                to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  40.  *                copyrights in this original Apple software (the "Apple Software"), to use,
  41.  *                reproduce, modify and redistribute the Apple Software, with or without
  42.  *                modifications, in source and/or binary forms; provided that if you redistribute
  43.  *                the Apple Software in its entirety and without modifications, you must retain
  44.  *                this notice and the following text and disclaimers in all such redistributions of
  45.  *                the Apple Software.  Neither the name, trademarks, service marks or logos of
  46.  *                Apple Computer, Inc. may be used to endorse or promote products derived from the
  47.  *                Apple Software without specific prior written permission from Apple.  Except as
  48.  *                expressly stated in this notice, no other rights or licenses, express or implied,
  49.  *                are granted by Apple herein, including but not limited to any patent rights that
  50.  *                may be infringed by your derivative works or by other works in which the Apple
  51.  *                Software may be incorporated.
  52.  *
  53.  *                The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  54.  *                WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  55.  *                WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  56.  *                PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  57.  *                COMBINATION WITH YOUR PRODUCTS.
  58.  *
  59.  *                IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  60.  *                CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  61.  *                GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  62.  *                ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  63.  *                OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  64.  *                (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  65.  *                ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  66.  * 
  67.  * 
  68.  */
  69. public abstract class ZooPane
  70. {
  71.     /**
  72.      *
  73.      */
  74.     public Compositor getCompositor()
  75.     {
  76.         return compositor;
  77.     }
  78.  
  79.     /**
  80.      * Called to do any setup after being set as the client of the QTCanvas.
  81.      * May be used to start effects running, movies playing, etc.
  82.      */
  83.     abstract public void start();
  84.  
  85.     /**
  86.      * Called to do clean up after being removed as the client of the QTCanvas.
  87.      * Should be used to stop effects running, movies playing, etc.
  88.      */
  89.     abstract public void stop();
  90.     
  91.     /**
  92.      * Sets the command name of the action event fired by this button.
  93.      * @param command The name of the action event command fired by this button
  94.      */
  95.     protected void setActionCommand(String command)
  96.     {
  97.         actionCommand = command;
  98.     }
  99.     
  100.     /**
  101.      * Adds the specified action listener to receive action events
  102.      * from this button.
  103.      * @param l the action listener
  104.      */
  105.     public void addActionListener(ActionListener l)
  106.     {
  107.         actionListener = AWTEventMulticaster.add(actionListener, l);
  108.     }
  109.  
  110.     /**
  111.      * Removes the specified action listener so it no longer receives
  112.      * action events from this button.
  113.      * @param l the action listener
  114.      */
  115.     public void removeActionListener(ActionListener l)
  116.     {
  117.         actionListener = AWTEventMulticaster.remove(actionListener, l);
  118.     }
  119.     
  120.     /**
  121.      * Fire an action event to the listeners.
  122.      */
  123.     protected void fireActionEvent()
  124.     {
  125.         if (actionListener != null)
  126.             actionListener.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, actionCommand));
  127.     }
  128.  
  129.     
  130.     public class PaneMouseListener extends MouseTargetAdapter implements MouseButtonListener
  131.     {
  132.         public PaneMouseListener( QDColor normalBlend, QDColor rollOverBlend, QDColor clickedBlend )
  133.         { 
  134.             normalGM   = new GraphicsMode( QDConstants.blend, normalBlend   );
  135.             rollOverGM = new GraphicsMode( QDConstants.blend, rollOverBlend );
  136.             clickedGM  = new GraphicsMode( QDConstants.blend, clickedBlend  );
  137.         }
  138.  
  139.         public void mouseTargetEntered( QTMouseEvent e ) // called when the mouse enters a region managed by the controller
  140.         {
  141.             isMouseInside = true;
  142.             try
  143.             {
  144.                 if ( e.getTarget() instanceof TwoDSprite )
  145.                 {
  146.                     TwoDSprite sp = (TwoDSprite) e.getTarget();
  147.                     if (isMousePressed)
  148.                         sp.setGraphicsMode( clickedGM );
  149.                     else
  150.                         sp.setGraphicsMode( rollOverGM );
  151.                 }
  152.             }
  153.             catch (QTException exc)
  154.             {    
  155.                 exc.printStackTrace();
  156.             }
  157.         }
  158.         
  159.         public void mouseTargetExited( QTMouseEvent e ) // called when the mouse exits a region managed by the controller
  160.         {
  161.             isMouseInside = false;
  162.             try
  163.             {
  164.                 if ( e.getTarget() instanceof TwoDSprite )
  165.                 {
  166.                     TwoDSprite sp = (TwoDSprite) e.getTarget();
  167.                     sp.setGraphicsMode( normalGM );
  168.                 }
  169.             }
  170.             catch (QTException exc)
  171.             {    
  172.                 exc.printStackTrace();
  173.             }
  174.         }
  175.  
  176.         public void mouseClicked(QTMouseEvent e) {}
  177.  
  178.         public void mousePressed( QTMouseEvent e )      // called when the mouse is pressed in a region managed by the controller
  179.         {
  180.             isMousePressed = true;
  181.             try
  182.             {
  183.                 if ( e.getTarget() instanceof TwoDSprite )
  184.                 {
  185.                     TwoDSprite sp = (TwoDSprite) e.getTarget();
  186.                     sp.setGraphicsMode( clickedGM );
  187.                 }
  188.             }
  189.             catch (QTException exc)
  190.             {    
  191.                 exc.printStackTrace();
  192.             }
  193.         }
  194.         
  195.         public void mouseReleased( QTMouseEvent e )    // called when the mouse is released in a region managed by the controller
  196.         {
  197.             isMousePressed = false;
  198.             try
  199.             {
  200.                 if ( e.getTarget() instanceof TwoDSprite )
  201.                 {
  202.                     TwoDSprite sp = (TwoDSprite) e.getTarget();
  203.                                         
  204.                     if (isMouseInside)
  205.                     {
  206.                         sp.setGraphicsMode( rollOverGM );
  207.  
  208.                          String area = (String) areas.get(sp);
  209.                         setActionCommand(area + ";" + e.getX() + ";" + e.getY());
  210.                         
  211.                         fireActionEvent();
  212.                     }
  213.                     else
  214.                         sp.setGraphicsMode( normalGM );
  215.                 }
  216.             }
  217.             catch (QTException exc)
  218.             {    
  219.                 exc.printStackTrace();
  220.             }
  221.         }
  222.         GraphicsMode rollOverGM = new GraphicsMode( QDConstants.blend, QDColor.darkGray );
  223.         GraphicsMode clickedGM = new GraphicsMode( QDConstants.blend, QDColor.lightGray );
  224.         GraphicsMode normalGM;
  225.     }
  226.     
  227.     protected Hashtable areas;
  228.     protected String actionCommand;
  229.     protected ActionListener actionListener = null;
  230.     protected Compositor compositor;
  231.     protected QTMouseTargetController ctr;
  232.     protected boolean isMouseInside;
  233.     protected boolean isMousePressed;
  234. }
  235.